VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "Counters"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private Const FIRST_COUNTER = 1
Private Const LAST_COUNTER = 15

Public Enum eCounterType
    ecComments = 1
    ecDeclares = 2
    ecElseIfs = 3
    ecGotos = 4
    ecHighestNestLevel = 5
    ecIifs = 6
    ecIfs = 7
    ecLines = 8
    ecLongLines = 9
    ecLoops = 10
    ecMultiDimCount = 11
    ecOneCharVars = 12
    ecParameters = 13
    ecSelects = 14
    ecWiths = 15
End Enum

Private mCounterNames As Variant

Private mCounters(FIRST_COUNTER To LAST_COUNTER) As Long

Public Sub Reset()

Dim idx As Long

    For idx = FIRST_COUNTER To LAST_COUNTER
        mCounters(idx) = 0
    Next
    
End Sub

Public Sub Add(which As eCounterType, qty As Long)
    mCounters(which) = mCounters(which) + qty
End Sub

Public Property Get FirstCounter() As Long
    FirstCounter = FIRST_COUNTER
End Property

Public Property Get LastCounter() As Long
    LastCounter = LAST_COUNTER
End Property

Public Function CounterValue(which As eCounterType)
    CounterValue = mCounters(which)
End Function

Public Function NestLevels() As Long
    NestLevels = mCounters(ecIfs) + mCounters(ecElseIfs) + mCounters(ecLoops) + mCounters(ecSelects)
End Function

Public Function CombinedIfs() As Long
    CombinedIfs = mCounters(ecIfs) + mCounters(ecElseIfs) + mCounters(ecIifs)
End Function

Public Sub SetCounter(which As eCounterType, newValue As Long)
    mCounters(which) = newValue
End Sub

Public Function Complexity() As Long

    Complexity = NestLevels _
    + mCounters(ecElseIfs) _
    + Int((mCounters(ecLines) - 1) / 10) + 1 _
    + Int((mCounters(ecDeclares) - 1) / 10) + 1 _
    + mCounters(ecMultiDimCount) _
    + Int((mCounters(ecParameters) - 1) / 2) + 1 _
    + mCounters(ecIifs) * 2 _
    + Int((mCounters(ecLongLines) - 1) / 5) + 1 _
    + mCounters(ecGotos) _
    + mCounters(ecHighestNestLevel) * mCounters(ecHighestNestLevel)
    
End Function

Public Function CounterName(which As eCounterType) As String
    CounterName = CStr(mCounterNames(which))
End Function

Private Sub Class_Initialize()

    mCounterNames = Array("", "Comments", "Declares", "ElseIfs", "Gotos", "HighestNestLevel", "Iifs" _
    , "Ifs", "Lines", "LongLines", "Loops", "MultiDimCount", "OneCharVars", "Parameters", "Selects", "Withs")

End Sub
